home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 4_2005-2006.ISO / data / Zips / Windows_Re190765712005.psc / Registry Fixer / frmMain.frm < prev    next >
Text File  |  2005-06-30  |  16KB  |  404 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
  3. Begin VB.Form frmMain 
  4.    Caption         =   "Windows Registry Error Deleter 1.0"
  5.    ClientHeight    =   4035
  6.    ClientLeft      =   165
  7.    ClientTop       =   555
  8.    ClientWidth     =   8985
  9.    Icon            =   "frmMain.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   4035
  12.    ScaleWidth      =   8985
  13.    StartUpPosition =   2  'CenterScreen
  14.    Begin MSComctlLib.ListView lvwRegErrors 
  15.       Height          =   2175
  16.       Left            =   0
  17.       TabIndex        =   3
  18.       Top             =   1800
  19.       Width           =   8895
  20.       _ExtentX        =   15690
  21.       _ExtentY        =   3836
  22.       View            =   2
  23.       LabelEdit       =   1
  24.       MultiSelect     =   -1  'True
  25.       LabelWrap       =   -1  'True
  26.       HideSelection   =   0   'False
  27.       Checkboxes      =   -1  'True
  28.       FullRowSelect   =   -1  'True
  29.       GridLines       =   -1  'True
  30.       _Version        =   393217
  31.       ForeColor       =   -2147483640
  32.       BackColor       =   -2147483643
  33.       BorderStyle     =   1
  34.       Appearance      =   1
  35.       NumItems        =   0
  36.    End
  37.    Begin VB.CommandButton cmdStartStop 
  38.       Caption         =   "&Start Scan"
  39.       Default         =   -1  'True
  40.       BeginProperty Font 
  41.          Name            =   "MS Sans Serif"
  42.          Size            =   24
  43.          Charset         =   0
  44.          Weight          =   700
  45.          Underline       =   0   'False
  46.          Italic          =   0   'False
  47.          Strikethrough   =   0   'False
  48.       EndProperty
  49.       Height          =   555
  50.       Left            =   0
  51.       TabIndex        =   0
  52.       Top             =   360
  53.       Width           =   8955
  54.    End
  55.    Begin VB.Label lblCurrentKey 
  56.       BorderStyle     =   1  'Fixed Single
  57.       Height          =   795
  58.       Left            =   1680
  59.       TabIndex        =   2
  60.       Top             =   960
  61.       Width           =   7155
  62.       WordWrap        =   -1  'True
  63.    End
  64.    Begin VB.Label lblStatus 
  65.       Caption         =   "Searching Key:"
  66.       Height          =   735
  67.       Left            =   120
  68.       TabIndex        =   1
  69.       Top             =   960
  70.       Width           =   1515
  71.    End
  72.    Begin VB.Menu mnuFile 
  73.       Caption         =   "&File"
  74.       Begin VB.Menu mnuStartStop 
  75.          Caption         =   "&Start Scan"
  76.       End
  77.       Begin VB.Menu mnuSeperator0 
  78.          Caption         =   "-"
  79.       End
  80.       Begin VB.Menu mnuRestore 
  81.          Caption         =   "&Restore Registry Backup"
  82.       End
  83.       Begin VB.Menu mnuSeperator1 
  84.          Caption         =   "-"
  85.       End
  86.       Begin VB.Menu mnuExit 
  87.          Caption         =   "E&xit"
  88.       End
  89.    End
  90.    Begin VB.Menu mnuRepair 
  91.       Caption         =   "------------------>&Repair<------------------"
  92.       Begin VB.Menu mnuCheckAll 
  93.          Caption         =   "&Check All Items"
  94.       End
  95.       Begin VB.Menu mnuUncheckAll 
  96.          Caption         =   "&Uncheck All Items"
  97.       End
  98.       Begin VB.Menu mnuSeparator2 
  99.          Caption         =   "-"
  100.       End
  101.       Begin VB.Menu mnuFix 
  102.          Caption         =   "&Delete All Checked Items"
  103.       End
  104.       Begin VB.Menu mnuSeperator3 
  105.          Caption         =   "-"
  106.       End
  107.       Begin VB.Menu mnuSearch 
  108.          Caption         =   "&Search for Missing File, Manually (Experts Only)"
  109.       End
  110.    End
  111.    Begin VB.Menu mnuHelp 
  112.       Caption         =   "&Help"
  113.       Begin VB.Menu mnuHelp2 
  114.          Caption         =   "&Help"
  115.       End
  116.       Begin VB.Menu mnuSeperator4 
  117.          Caption         =   "-"
  118.       End
  119.       Begin VB.Menu mnuAbout 
  120.          Caption         =   "&About"
  121.       End
  122.    End
  123. End
  124. Attribute VB_Name = "frmMain"
  125. Attribute VB_GlobalNameSpace = False
  126. Attribute VB_Creatable = False
  127. Attribute VB_PredeclaredId = True
  128. Attribute VB_Exposed = False
  129. Option Explicit
  130. Dim WithEvents cReg As cRegSearch
  131. Attribute cReg.VB_VarHelpID = -1
  132.  
  133. 'Stop or start scanning for errors
  134. Private Sub cmdStartStop_Click()
  135.     If cmdStartStop.Caption = "&Start Scan" Then mnuStartStop.Caption = "&Stop Scan"
  136.     If cmdStartStop.Caption = "&Stop Scan" Then
  137.         Caption = "Exiting..."
  138.         cReg.StopSearch
  139.         Exit Sub
  140.     End If
  141.     If lvwRegErrors.ListItems.Count > 0 Then mnuRepair.Visible = True
  142.     cmdStartStop.Caption = "&Stop Scan"
  143.     If lvwRegErrors.Visible = False Then
  144.         Top = Top / 2
  145.         Height = Height * 2
  146.         lvwRegErrors.Visible = True
  147.     End If
  148.     lvwRegErrors.ListItems.Clear
  149.     lblStatus = "Searching key:"
  150.     lblCurrentKey = ""
  151.  
  152.     cReg.RootKey = 0
  153.     cReg.SubKey = ""
  154.     cReg.SearchFlags = KEY_NAME * 0 + VALUE_NAME * 1 + VALUE_VALUE * 1 + WHOLE_STRING * 0
  155.     cReg.SearchString = "C:\"
  156.     Caption = "Scanning..."
  157.     cReg.DoSearch
  158.     If lvwRegErrors.ListItems.Count = 0 Then mnuRepair.Visible = False
  159. End Sub
  160.  
  161. 'The search is finished
  162. Private Sub cReg_SearchFinished(ByVal lReason As Long)
  163.     If lReason = 0 Then
  164.         lblCurrentKey = "Done!"
  165.     ElseIf lReason = 1 Then
  166.         lblCurrentKey = "Terminated by user!"
  167.     Else
  168.         lblCurrentKey = "An Error occured! Err number = " & lReason
  169.         'Err.Raise lReason
  170.     End If
  171.     cmdStartStop.Caption = "&Start Scan"
  172.     mnuRepair.Visible = True
  173.     lblStatus = "Search result:"
  174.     Caption = "Finished Scanning (" & lvwRegErrors.ListItems.Count & " errors found)"
  175. End Sub
  176.  
  177. 'If a registry error is found
  178. Private Sub cReg_SearchFound(ByVal sRootKey As String, ByVal sKey As String, ByVal sValue As Variant, ByVal lFound As FOUND_WHERE)
  179.     Dim sTemp As String
  180.     Dim FileorPath As String
  181.     Dim lvItm As ListItem
  182.     Select Case lFound
  183.     Case FOUND_IN_KEY_NAME
  184.         sTemp = "KEY_NAME"
  185.     Case FOUND_IN_VALUE_NAME
  186.         sTemp = "VALUE NAME"
  187.     Case FOUND_IN_VALUE_VALUE
  188.         sTemp = "VALUE VALUE"
  189.     End Select
  190.  
  191.     'Fix up the file or path so that it's compatible with the FileorFolderExists function
  192.     FileorPath = sValue
  193.  
  194.     'Find the start of the path or filename (Example:"h6j65ej(C:\Test)")
  195.     If InStr(1, FileorPath, "C:\") Then FileorPath = Mid(FileorPath, InStr(1, FileorPath, "C:\"))
  196.     If InStr(1, FileorPath, "c:\") Then FileorPath = Mid(FileorPath, InStr(1, FileorPath, "c:\"))
  197.  
  198.     'Remove everything after the path. This definitely doesn't work for all values.
  199.     '(Example:"C:\blablablablablablablabla?5784846\84585")
  200.     If InStr(1, FileorPath, "/") > 0 Then FileorPath = Mid(FileorPath, 1, InStr(1, FileorPath, "/") - 1)
  201.     If InStr(1, FileorPath, "*") > 0 Then FileorPath = Mid(FileorPath, 1, InStr(1, FileorPath, "*") - 1)
  202.     If InStr(1, FileorPath, "?") > 0 Then FileorPath = Mid(FileorPath, 1, InStr(1, FileorPath, "?") - 1)
  203.     If InStr(1, FileorPath, Chr(34)) > 0 Then FileorPath = Mid(FileorPath, 1, InStr(1, FileorPath, Chr(34)) - 1)
  204.     If InStr(1, FileorPath, "<") > 0 Then FileorPath = Mid(FileorPath, 1, InStr(1, FileorPath, "<") - 1)
  205.     If InStr(1, FileorPath, ">") > 0 Then FileorPath = Mid(FileorPath, 1, InStr(1, FileorPath, ">") - 1)
  206.     If InStr(1, FileorPath, "|") > 0 Then FileorPath = Mid(FileorPath, 1, InStr(1, FileorPath, "|") - 1)
  207.     If InStr(1, FileorPath, ",") > 0 Then FileorPath = Mid(FileorPath, 1, InStr(1, FileorPath, ",") - 1)
  208.     If InStr(1, FileorPath, "(") > 0 Then FileorPath = Mid(FileorPath, 1, InStr(1, FileorPath, "(") - 1)
  209.     If InStr(1, FileorPath, ";") > 0 Then FileorPath = Mid(FileorPath, 1, InStr(1, FileorPath, ";") - 1)
  210.  
  211.     'I don 't know if it's just my computer, but some registry values somehow didn't contain "C:\"
  212.     If InStr(1, FileorPath, "C:\") = 0 Then FileorPath = "C:\"
  213.  
  214.     'Remove everything before the path or file. The same as the other one except this is for specific extensions
  215.     '(Example:"C:\lalalalalalalala\idfjb.dll\50")
  216.     If InStr(1, FileorPath, ".EXE ") > 0 Then FileorPath = Mid(FileorPath, 1, InStr(1, FileorPath, ".EXE ") + 3)
  217.     If InStr(1, FileorPath, ".exe ") > 0 Then FileorPath = Mid(FileorPath, 1, InStr(1, FileorPath, ".exe ") + 3)
  218.     If InStr(1, FileorPath, ".SYS ") > 0 Then FileorPath = Mid(FileorPath, 1, InStr(1, FileorPath, ".SYS ") + 3)
  219.     If InStr(1, FileorPath, ".sys ") > 0 Then FileorPath = Mid(FileorPath, 1, InStr(1, FileorPath, ".sys ") + 3)
  220.     If InStr(1, FileorPath, ".EXE\") > 0 Then FileorPath = Mid(FileorPath, 1, InStr(1, FileorPath, ".EXE\") + 3)
  221.     If InStr(1, FileorPath, ".exe\") > 0 Then FileorPath = Mid(FileorPath, 1, InStr(1, FileorPath, ".exe\") + 3)
  222.     If InStr(1, FileorPath, ".DLL\") > 0 Then FileorPath = Mid(FileorPath, 1, InStr(1, FileorPath, ".DLL\") + 3)
  223.     If InStr(1, FileorPath, ".dll\") > 0 Then FileorPath = Mid(FileorPath, 1, InStr(1, FileorPath, ".dll\") + 3)
  224.     If InStr(1, FileorPath, ".OCX\") > 0 Then FileorPath = Mid(FileorPath, 1, InStr(1, FileorPath, ".OCX\") + 3)
  225.     If InStr(1, FileorPath, ".ocx\") > 0 Then FileorPath = Mid(FileorPath, 1, InStr(1, FileorPath, ".ocx\") + 3)
  226.     If InStr(1, FileorPath, "*") > 0 Then FileorPath = Mid(FileorPath, 1, InStr(1, FileorPath, "*") - 1)
  227.  
  228.     '%1 is used for file associations
  229.     '(Example:"C:\WINDOWS\NOTEPAD.EXE %1")
  230.     FileorPath = Replace(FileorPath, " %1", "")
  231.  
  232.     'Check if the value is an invalid path or file
  233.     'If it is, then it adds the value to lvwRegErrors and displays the current number of errors, so far.
  234.     If FileorFolderExists(FileorPath) = False Then
  235.         With lvwRegErrors
  236.             Set lvItm = .ListItems.Add(, , sTemp)
  237.             lvItm.SubItems(1) = sRootKey
  238.             lvItm.SubItems(2) = sKey
  239.             lvItm.SubItems(3) = sValue
  240.         End With
  241.         LV_AutoSizeColumn lvwRegErrors
  242.         Me.Caption = "Windows Registry Error Deleter 1.0 (" & lvwRegErrors.ListItems.Count & " errors found)"
  243.         lblStatus.Caption = "Searching Key:" & vbCrLf & "(" & lvwRegErrors.ListItems.Count & " errors found)"
  244.     End If
  245.     
  246.     Set lvItm = Nothing
  247. End Sub
  248.  
  249. 'I don't know if I should remove it
  250. Private Sub cReg_SearchKeyChanged(ByVal sFullKeyName As String)
  251. 'Note: This event cause a lot of printing.
  252. 'To increase performance remove this event.
  253.     If Me.WindowState <> vbMinimized Then lblCurrentKey = sFullKeyName
  254. End Sub
  255.  
  256. 'Setup everything
  257. Private Sub Form_Load()
  258.     mnuRepair.Visible = False
  259.     With lvwRegErrors
  260.         .View = lvwReport
  261.         .ColumnHeaders.Add , , "Found at:"
  262.         .ColumnHeaders.Add , , "RootKey"
  263.         .ColumnHeaders.Add , , "SubKey"
  264.         .ColumnHeaders.Add , , "Value"
  265.     End With
  266.  
  267.     Me.Height = (Me.Height - Me.ScaleHeight) + lvwRegErrors.Top
  268.     
  269.     Me.Move Me.Left, Me.Top, Screen.Width / 1.5, Screen.Height / 1.5
  270.     Me.Move (Screen.Width / 2) - (Me.ScaleWidth / 2), (Screen.Height / 2) - (Me.ScaleHeight / 2)
  271.     Set cReg = New cRegSearch
  272. End Sub
  273.  
  274. 'Resize the controls if the form is resized
  275. Private Sub Form_Resize()
  276.     On Error GoTo ERROR_HANDLER
  277.     If Me.WindowState = vbMinimized Then Exit Sub
  278.     If Me.WindowState = vbMaximized Then lvwRegErrors.Visible = True
  279.     cmdStartStop.Move 0, cmdStartStop.Top, Me.ScaleWidth
  280.     cmdStartStop.Left = Me.ScaleWidth - cmdStartStop.Width
  281.     lblCurrentKey.Width = cmdStartStop.Left + cmdStartStop.Width - lblCurrentKey.Left
  282.     lvwRegErrors.Move 0, lblCurrentKey.Top + lblCurrentKey.Height, Me.ScaleWidth, Me.ScaleHeight - 1800
  283.     lvwRegErrors.ColumnHeaders(3).Width = (lvwRegErrors.Width - lvwRegErrors.ColumnHeaders(1).Width * 2) / 2 - 600
  284.     lvwRegErrors.ColumnHeaders(4).Width = lvwRegErrors.ColumnHeaders(3).Width
  285.     LV_AutoSizeColumn lvwRegErrors
  286.     Exit Sub
  287. ERROR_HANDLER:
  288. End Sub
  289.  
  290. 'I'm not sure if this is necessary, but I guess it's just to clean up and exit this program
  291. Private Sub Form_Unload(Cancel As Integer)
  292.     cReg.StopSearch
  293.     Set cReg = Nothing
  294. End Sub
  295.  
  296. 'If you select multiple items, they will be checked if their unchecked and unchecked if their checked
  297. Private Sub lvwRegErrors_ItemClick(ByVal Item As MSComctlLib.ListItem)
  298.     If Item.Checked = False Then
  299.         Item.Checked = True
  300.     Else
  301.         Item.Checked = False
  302.     End If
  303. End Sub
  304.  
  305. 'If the the right clicks on lvwRegErrors, mnuRepair become visible
  306. Private Sub lvwRegErrors_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  307.     If Button = 2 And mnuRepair.Visible = True Then
  308.         PopupMenu mnuRepair
  309.     End If
  310. End Sub
  311.  
  312. 'About menu
  313. Private Sub mnuAbout_Click()
  314.     MsgBox "VB Registry Fixer 1.0" & vbCrLf & vbCrLf & "If you use this program, you take full responsibility for any damages this program may do to your computer.", vbInformation, "VB Registry Fixer 1.0"
  315. End Sub
  316.  
  317. Private Sub mnuExit_Click()
  318. End
  319. End Sub
  320.  
  321. 'Creates a registry backup of all the values about to be deleted and then deletes them
  322. Private Sub mnuFix_Click()
  323.     Dim i As Integer, nLoop As Single, m As Single
  324.     Dim NOTRemoved As Integer
  325.     Dim BackupFilename As String
  326.     On Error Resume Next
  327.  
  328. 'I don't think this is necessary, but if the registry backup takes a while, this program tells the user to wait.
  329.     lblCurrentKey.FontSize = 24
  330.     lblCurrentKey.FontBold = True
  331.     lblCurrentKey.Caption = "Creating Registry Backup..."
  332.     BackupReg
  333.     lblCurrentKey.FontSize = 8
  334.     lblCurrentKey.FontBold = False
  335.     lblCurrentKey.Caption = ""
  336.  
  337.     Do Until FileorFolderExists(App.Path & "\RegBackup\Backups #" & i & " (" & Replace(Replace(Now, "/", "-"), ":", ";") & ").reg") = False
  338.     BackupFilename = App.Path & "\RegBackup\Backups #" & i & " (" & Replace(Replace(Now, "/", "-"), ":", ";") & ").reg"
  339.     i = i + 1
  340.     Loop
  341.     
  342.     'Tell the user that this program has created a backup and and to restore the registry if the user's computer acts abnormal
  343.     MsgBox "This program has created a backup of all of the registry values that are about to be deleted. If you experience problems after using this, keep pressing F8 when you start up your computer and select Safe Mode and open up " & BackupFilename, vbInformation, "Important"
  344.     
  345.     'Loop through every item in lvwRegErrors
  346.     For i = 1 To lvwRegErrors.ListItems.Count
  347.         'If the item is checked
  348.         If lvwRegErrors.ListItems.Item(i).Checked = True Then
  349.             'Delete the registry error and mark the item as removed
  350.             DeleteValue GetClassKey(lvwRegErrors.ListItems.Item(i).SubItems(1)), lvwRegErrors.ListItems.Item(i).SubItems(2), lvwRegErrors.ListItems.Item(i).SubItems(3)
  351.             lvwRegErrors.ListItems.Item(i).Text = "REMOVED"
  352.             NOTRemoved = NOTRemoved + 1
  353.         End If    'If you remove the if...then line above then also remove this line.
  354.     Next
  355.     
  356.     'Tell the user how many items that were not removed
  357.  
  358.     MsgBox "VB Registry Fixer has successfully fixed your registry. There were " & lvwRegErrors.ListItems.Count - NOTRemoved & " registry values that were NOT removed."
  359. End Sub
  360.  
  361. 'Help menu
  362. Private Sub mnuHelp2_Click()
  363.     MsgBox "Step 1 - Click Start Scan" & vbCrLf & vbCrLf & _
  364.     "Step 2 - When the scan is finished, check all the items on the list that you want to delete. I highly recommend that you look carefully for what items you want to remove and not just check all of them." & vbCrLf & vbCrLf & _
  365.     "Step 3 - Right click the list and click 'Delete All Checked Items'", vbInformation, "Help"
  366. End Sub
  367.  
  368. 'Checked all items in lvwRegErrors
  369. Private Sub mnuCheckAll_Click()
  370.     Dim i As Integer
  371.     For i = 1 To lvwRegErrors.ListItems.Count
  372.         lvwRegErrors.ListItems.Item(i).Checked = True
  373.     Next
  374. End Sub
  375.  
  376. Private Sub mnuRestore_Click()
  377. frmRestore.Show vbModal
  378. End Sub
  379.  
  380. Private Sub mnuSearch_Click()
  381. frmSearch.Show vbModal
  382. End Sub
  383.  
  384. 'Uncheck all checked items in lvwRegErrors
  385. Private Sub mnuUncheckAll_Click()
  386.     Dim i As Integer
  387.     For i = 1 To lvwRegErrors.ListItems.Count
  388.         lvwRegErrors.ListItems.Item(i).Checked = False
  389.     Next
  390. End Sub
  391.  
  392. 'Start or stop the scan
  393. Private Sub mnuStartStop_Click()
  394.     If mnuStartStop.Caption = "&Start Scan" Then
  395.         cmdStartStop_Click
  396.         mnuStartStop.Caption = "&Stop Scan"
  397.     End If
  398.     
  399.     If mnuStartStop.Caption = "&Stop Scan" Then
  400.         cmdStartStop_Click
  401.         mnuStartStop.Caption = "&Start Scan"
  402.     End If
  403. End Sub
  404.